package com.cdd.eduservice.controller.front;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cdd.commonutils.R;
import com.cdd.eduservice.entity.EduCourse;
import com.cdd.eduservice.entity.EduTeacher;
import com.cdd.eduservice.service.IEduCourseService;
import com.cdd.eduservice.service.IEduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherFront")
@CrossOrigin
public class EduTeacherFrontController {

    @Autowired
    private IEduTeacherService eduTeacherService;

    @Autowired
    private IEduCourseService eduCourseService;

    @GetMapping("pageTeacher/{current}/{limit}")
    public R pageTeacher(@PathVariable long current, @PathVariable long limit) {
        Page<EduTeacher> page = new Page<>(current,limit);
        // 分页实现功能不同，这次较为底层，需返回所有数据
        Map<String, Object> map = eduTeacherService.getPageTeacher(page);
        return R.ok().data(map);
    }

    @GetMapping("getTeacherInfo/{id}")
    public R getTeacherInfo(@PathVariable String id) {
        EduTeacher eduTeacher = eduTeacherService.getById(id);
        //根据讲师id查询这个讲师的课程列表
        List<EduCourse> courseList = eduCourseService.selectByTeacherId(id);
        return R.ok().data("teacher", eduTeacher).data("courseList", courseList);
    }
}
